﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>开发流程</title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>开发流程</h3>
    <p>
        <b>1.NFinal项目分两种，一种是宿主项目，一种是插件项目。</b><br/>
        宿主项目是Web服务器，比如WebApplication项目，OwinHost项目等。
        而插件项目是供宿主项目调用的项目，一般为.net library项目。
        以下操作只能在VS2017下进行：
    <p>
        1.创建基于.net core 1.1的项目。<br/>
        <img src="../../Content/images/SimpleWebApp/新建项目.jpg" /><br />
        2.选择.net core 1.1以及空Web项目<br />
        <img src="../../Content/images/SimpleWebApp/项目类型.jpg" /><br />
        3.打开Nuget管理器<br />
        <img src="../../Content/images/SimpleWebApp/打开Nuget.jpg" /><br />
        4.搜索NFinal包<br />
        <img src="../../Content/images/SimpleWebApp/搜索Nuget包.jpg" /><br />
        5.安装Nuget包<br />
        <img src="../../Content/images/SimpleWebApp/安装Nuget.jpg" /><br />
        6.在bin/Debug/netcoreapp1.1下新建nfinal.json<br />
        <pre class="brush:javascript;">
        {
            //调试设置
            "debug": {
            "enable": true,
            "url": "http://localhost:59843",
            "directory": "/Debug"
            },
            //项目类型
            "projectType": "Web",
            "server": {
            "url": "http://www.domain.com",
            "indexDocument": "/Index.html"
            }
        }
        </pre>
        其中的debug.url必须和该项目属性中的一致。<br />
        右键点击项目，选择属性->Web选项。<br />
        <img src="../../Content/images/SimpleWebApp/调试Url设置.jpg" /><br />
        7.在bin/Debug/netcoreapp1.1/新建 Plugs/SimpleWebApp目录。并于该目录下新建plug.json<br/>
        此处把宿主项目的程序集作为插件加载。<br />
        <pre class="brush:javascript;">
        {
            "plug": {
            "enable": true,
            "name": "Main",
            "urlPrefix": null,
            "description": "网站",
            //当开发完成后，dll插件拷贝到当前目录下时，其路径为"/Plugs/CorePlug/NFinalCorePlug.dll".
            //这时插件就可以复制到Plugs目录下就能实现相应功能。
            "assemblyPath": "./SimpleWebApp.dll"
            },
            //用户自定义设置
            "appSettings": {
            "key": "value"
            },
            //连接字符串设置
            "connectionStrings": {
            "Common": {
                "connectionString": "Data Source=|ModuleDataDirectory|Common.db;Pooling=true;FailIfMissing=false",
                "providerName": "System.Data.SQLite"
            }
            },
            "verbs": [ "GET", "POST", "HEAD", "DEBUG" ],
            //Session设置
            "sessionState": {
            "cookieName": "session_id",
            "mode": "Redis",
            "stateConnectionString": "localhost",
            "timeout": 20,
            "prefix": ""
            },
            //Url设置
            "url": {
            "prefix": "",
            "extension": ".html",
            "defaultDocument": "index.html"
            },
            //Cookie设置
            "cookie": {
            "prefix": ""
            },
            //默认皮肤
            "defaultSkin": null,
            //用户自定义错误
            "customErrors": {
            "defaultRedirect": "Err.htm",
            "mode": "Off",
            "errors": [
                {
                "statusCode": 403,
                "redirect": "NoAccess.htm"
                },
                {
                "statusCode": 404,
                "redirect": "FileNotFound.htm"
                }
            ]
            }
        }
        </pre>
        8.把根目录下Startup类中的Configure方法的内容改为
        <pre class="brush:csharp;">
        public class Startup
        {
            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
            {
                app.UseMiddleware&lt;NFinal.Middleware.CoreMiddleware>();
            }
        }
        </pre>
        9.在根目录下新建BaseController
        <pre class="brush:csharp;">
            public class BaseController : NFinal.CoreAction
            {
                
            }
        </pre>
        10.在根目录下新建Controllers，并新建IndexController类
        <pre class="brush:csharp;">
            public class IndexController : BaseController
            {
                public void Index()
                {
                    this.Write("Hello World!");
                }
            }
        </pre>
        11.启动项目。在根目录下会生成/Debug/Index/Index.html,启动该调试文件。
        浏览器输出Hello World!
    </p>
    
</body>
</html>
